<template>
	<view class="inventoryDetails">
		<view class="inventoryDetails-top">
			<view class="inventoryDetails-top-address">
				<view class="inventoryDetails-top-address-left">
					<image class="inventoryDetails-top-address-left-img"
						src="https://www.zzzsyh.com/applets/agent/agent/address.png" mode="">
					</image>
				</view>
				<view class="inventoryDetails-top-address-right">
					<view class="inventoryDetails-top-address-right-li inventoryDetails-top-address-right-li-1">
						<text class="inventoryDetails-top-address-right-li-left">收货人</text>：
						<view class="inventoryDetails-top-address-right-li-right inventoryDetails-top-address-right-li-right1">
							<text>{{msg.orderName}}</text>
							<text style="margin-left: 24rpx;">{{msg.orderPhone}}</text>
						</view>
					</view>
					<view class="inventoryDetails-top-address-right-li">
						<text class="inventoryDetails-top-address-right-li-left">收货地址</text>：
						<text class="inventoryDetails-top-address-right-li-right">{{msg.orderAddress}}</text>
					</view>
					<view class="inventoryDetails-top-address-right-li">
						<text class="inventoryDetails-top-address-right-li-left">下单时间</text>：
						<text class="inventoryDetails-top-address-right-li-right">{{msg.createTime}}</text>
					</view>
				</view>
			</view>
			<view class="inventoryDetails-top-shop">
				<view class="inventoryDetails-top-shop-head">
					<view class="inventoryDetails-top-shop-head-left">
						<image class="inventoryDetails-top-shop-head-left-img"
							src="https://www.zzzsyh.com/applets/agent/agent/house.png" mode=""></image>
						<text class="inventoryDetails-top-shop-head-left-txt font_blod">{{msg.factoryName}}</text>
					</view>
					<image class="inventoryDetails-top-shop-head-right-img" @click="cli_playPhone(msg.factoryPhone)"
						src="https://www.zzzsyh.com/applets/agent/agent/phone-two.png" mode=""></image>
				</view>
				<view class="inventoryDetails-top-shop-main">
					<view class="inventoryDetails-top-shop-main-left">
						<image class="inventoryDetails-top-shop-main-left-img" v-if="msg.factoryImages"
							:src=msg.factoryImages mode=""></image>
						<image class="inventoryDetails-top-shop-main-left-img" v-else
							src='https://www.zzzsyh.com/applets/agent/agent/shop.png' mode=""></image>
					</view>
					<view class="inventoryDetails-top-shop-main-right">
						<view class="inventoryDetails-top-shop-main-right-top">
							优选厂家
						</view>
						<view class="inventoryDetails-top-shop-main-right-btm" v-if="msg.factoryProducts">
							合作产品：{{msg.factoryProducts}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="inventoryDetails-li-head">
			<text class="inventoryDetails-li-head-txt1"></text>
			<text class="inventoryDetails-li-head-txt2 font_blod">预订清单</text>
		</view>
		<view class="inventoryDetails-list">
			<view class="inventoryDetails-li" v-for="(ite, ind) of msg.zsyhAgentOrderRelList" :key="ind">
				<view class="inventoryDetails-li-left">
					<image class="inventoryDetails-li-left-img" @click="previewImage(ite.attributeLogo, ind)"
						:src=ite.attributeLogo mode=""></image>
				</view>
				<view class="inventoryDetails-li-right">
					<view class="inventoryDetails-li-right-top font_blod">
						{{ite.attributeName}}
					</view>
					<view class="inventoryDetails-li-right-btm">
						<view class="inventoryDetails-li-right-btm-left">
							<text class="inventoryDetails-li-right-btm-left-txt1">￥</text>
							<text class="inventoryDetails-li-right-btm-left-txt2" v-if="msg.orderState == 0 || msg.orderState == 1 || msg.orderState == 2">{{ite.orderPrice}}</text>
							<text class="inventoryDetails-li-right-btm-left-txt2" v-else>{{ite.orderSellPrice}}</text>
							<text class="inventoryDetails-li-right-btm-left-txt3">/{{ite.partsUnit}}</text>
						</view>
						<view class="inventoryDetails-li-right-btm-right" v-if="msg.orderState == 0 || msg.orderState == 1 || msg.orderState == 2">
							<text class="inventoryDetails-li-right-btm-right-txt1">预订数量:</text>
							<text class="inventoryDetails-li-right-btm-right-txt2 font_blod">{{ite.orderCount}}</text>
							<text class="inventoryDetails-li-right-btm-right-txt3">{{ite.partsUnit}}</text>
						</view>
					</view>
					<view class="inventoryDetails-li-right-btm" v-if="msg.orderState == 3 || msg.orderState == 4">
						<view class="inventoryDetails-li-right-btm-right">
							<text class="inventoryDetails-li-right-btm-right-txt1">预订数量:</text>
							<text class="inventoryDetails-li-right-btm-right-txt2 font_blod">{{ite.orderCount}}</text>
							<text class="inventoryDetails-li-right-btm-right-txt3">{{ite.partsUnit}}</text>
						</view>
						<view class="inventoryDetails-li-right-btm-right">
							<text class="inventoryDetails-li-right-btm-right-txt1">发货数量:</text>
							<text class="inventoryDetails-li-right-btm-right-txt2 font_blod">{{ite.orderSellCount}}</text>
							<text class="inventoryDetails-li-right-btm-right-txt3">{{ite.partsUnit}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="inventoryDetails-btn">
			<image class="inventoryDetails-btn-img" src="https://www.zzzsyh.com/applets/agent/agent/yuDing-1.png"
				mode=""></image>
			<view class="inventoryDetails-btn-cen" :class="[msg.orderState == 4? 'inventoryDetails-btn-cen-two' : '']">
				<view class="inventoryDetails-btn-cen-top"
					:class="[msg.orderState == 4? 'inventoryDetails-btn-cen-top-two' : '']">
					<text class="inventoryDetails-btn-cen-top-txt1">合计:</text>
					<text class="inventoryDetails-btn-cen-top-txt2 font_blod">￥</text>
					<text class="inventoryDetails-btn-cen-top-txt3 font_blod"
						v-if="msg.orderState == 0 || msg.orderState == 1 || msg.orderState == 2">{{msg.orderBeginMoney}}</text>
					<text class="inventoryDetails-btn-cen-top-txt3" v-else>{{msg.orderEndMoney}}</text>
				</view>
				<view class="inventoryDetails-btn-cen-bottom">
					共 {{msg.zsyhAgentOrderRelList.length}} 个商品
				</view>
			</view>
			<view class="inventoryDetails-btn-right font_blod" v-if="msg.orderState == 1 || msg.orderState == 2"
				@click="cli_cancel()">
				取消订单
			</view>
			<view @click="settleAccounts" class="inventoryDetails-btn-right inventoryDetails-btn-right-two font_blod"
				v-if="msg.orderState == 3">
				确认结算
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				id: '',
				msg: {
					zsyhAgentOrderRelList: []
				}
			}
		},
		onLoad(val) {
			if (val.id) {
				this.id = val.id
			}
		},
		mounted() {
			this.getReserveOrderDetails()
		},
		methods: {
			// 图片预览
			previewImage(item, index) {
				console.log(item);
				let lis = item.split()
				wx.previewImage({
					current: 0, // 当前显示图片的http链接
					urls: lis // 需要预览的图片http链接列表
				})
			},
			// 拨打电话
			cli_playPhone(val) {
				uni.makePhoneCall({
					phoneNumber: val //仅为示例
				});
			},
			// 取消订单
			cli_cancel() {
				let _that = this
				uni.showModal({
					title: '提示',
					content: '确定取消订单？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_that.cancelOrder()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			cancelOrder() {
				let _that = this
				uni.request({
					url: allapi.cancelOrder,
					data: {
						id: this.msg.id
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						_that.getReserveOrderDetails()
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					}
				})
			},
			// 确认结算
			settleAccounts() {
				let _that = this
				uni.request({
					url: allapi.settleAccounts,
					data: {
						id: this.msg.id
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						_that.getReserveOrderDetails()
					}
				})
			},
			// 获取数据列表
			getReserveOrderDetails() {
				uni.request({
					url: allapi.getReserveOrderDetails,
					data: {
						id: this.id
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						this.msg = dat
					}
				})
			},
		}
	}
</script>

<style scoped>
	.inventoryDetails {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
	}

	.inventoryDetails-top {
		height: 394rpx;
		background: linear-gradient(180deg, #28CD50 0%, rgba(243, 245, 246, 0.79) 100%);
	}

	.inventoryDetails-top-address {
		margin: 0 10rpx;
		height: 224rpx;
		background-image: url('https://www.zzzsyh.com/applets/agent/agent/14.png');
		background-repeat: no-repeat;
		background-size: 100%;
		display: flex;
		align-items: center;
	}

	.inventoryDetails-top-address-left {
		margin-left: 38rpx;
		margin-right: 24rpx;
	}

	.inventoryDetails-top-address-left-img {
		width: 32rpx;
		height: 32rpx;
	}

	.inventoryDetails-top-address-right {
		flex: 1;
		margin-right: 64rpx;
	}

	.inventoryDetails-top-address-right-li {
		line-height: 32rpx;
		margin: 8rpx 0;
		display: flex;
		align-items: center;
		color: #999999;
		font-size: 24rpx;
	}

	.inventoryDetails-top-address-right-li-1 {
		/* line-height: 44rpx; */
	}

	.inventoryDetails-top-address-right-li-left {
		width: 100rpx;
		color: #999999;
		font-size: 24rpx;
		text-align: justify;
		text-align-last: justify;

	}

	.inventoryDetails-top-address-right-li-right {
		color: #333333;
		font-weight: 400;
		font-size: 24rpx;
		flex: 1;
	}

	.inventoryDetails-top-address-right-li-right1 {
		font-size: 32rpx;
	}

	.inventoryDetails-top-shop {
		margin: 24rpx;
		padding: 24rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
	}

	.inventoryDetails-top-shop-head {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.inventoryDetails-top-shop-head-left {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.inventoryDetails-top-shop-head-left-img {
		width: 42rpx;
		height: 42rpx;
	}

	.inventoryDetails-top-shop-head-left-txt {
		font-size: 32rpx;
		color: #333333;
		flex: 1;
		margin-left: 24rpx;
	}

	.inventoryDetails-top-shop-head-right-img {
		width: 72rpx;
		height: 48rpx;
	}

	.inventoryDetails-top-shop-main {
		display: flex;
		margin-top: 24rpx;
	}

	.inventoryDetails-top-shop-main-left-img {
		width: 96rpx;
		height: 96rpx;
		background: #CCCCCC;
		border-radius: 50%;
	}

	.inventoryDetails-top-shop-main-right {
		flex: 1;
		margin-left: 16rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.inventoryDetails-top-shop-main-right-top {
		font-size: 28rpx;
		color: #333333;
		font-weight: 400;
	}

	.inventoryDetails-top-shop-main-right-btm {
		color: #666666;
		font-weight: 400;
		font-size: 24rpx;
		margin-top: 20rpx;
	}

	.inventoryDetails-li-head {
		display: flex;
		align-items: center;
		margin-top: 118rpx;
		margin-bottom: 2rpx;
	}

	.inventoryDetails-li-head-txt1 {
		width: 10rpx;
		height: 34rpx;
		background: #58D26F;
		border-radius: 5rpx;
		margin: 0 24rpx;
	}

	.inventoryDetails-li-head-txt2 {
		font-size: 32rpx;
		color: #333333;
	}

	.inventoryDetails-list {
		flex: 1;
		background: #FFFFFF;
		margin: 24rpx;
		border-radius: 16rpx;
		padding-bottom: 24rpx;
		overflow: auto;
	}

	.inventoryDetails-li {
		margin: 24rpx;
		margin-top: 40rpx;
		border-bottom: 1rpx solid #EEEEEE;
		display: flex;
		padding-bottom: 24rpx;
		/* background: red; */
	}

	.inventoryDetails-li-left {}

	.inventoryDetails-li-left-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 12rpx;
	}

	.inventoryDetails-li-right {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 24rpx;
		margin-right: 32rpx;
	}

	.inventoryDetails-li-right-top {
		line-height: 40rpx;
		font-size: 28rpx;
		color: #333333;
		margin-top: 16rpx;
	}

	.inventoryDetails-li-right-btm {
		display: flex;
		justify-content: space-between;
		margin-bottom: 12rpx;
	}

	.inventoryDetails-li-right-btm-left-txt1 {
		font-size: 24rpx;
		color: #333333;
		font-weight: 400;
	}

	.inventoryDetails-li-right-btm-left-txt2 {
		font-size: 36rpx;
		font-weight: 400;
		color: #333333;
	}

	.inventoryDetails-li-right-btm-left-txt3 {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}

	.inventoryDetails-li-right-btm-right {
		display: flex;
		align-items: center;
	}

	.inventoryDetails-li-right-btm-right-txt1 {
		font-size: 24rpx;
		color: #333333;
		font-weight: 400;
	}

	.inventoryDetails-li-right-btm-right-txt2 {
		width: 80rpx;
		font-size: 32rpx;
		color: #28CD50;
		text-align: center;
	}

	.inventoryDetails-li-right-btm-right-txt3 {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}

	.inventoryDetails-btn {
		margin: 0 16rpx;
		height: 120rpx;
		background: #313131;
		border-radius: 24rpx;
		display: flex;
		align-items: center;
		padding: 0 16rpx;
		margin-bottom: calc(env(safe-area-inset-bottom) + 32rpx)
	}

	.inventoryDetails-btn-img {
		width: 74rpx;
		height: 94rpx;
	}

	.inventoryDetails-btn-cen {
		flex: 1;
		margin-left: 16rpx;
	}

	.inventoryDetails-btn-cen-two {
		display: flex;
		flex-direction: row-reverse;
		justify-content: space-between;
		align-items: center;
	}

	.inventoryDetails-btn-cen-top {
		display: flex;
		align-items: center;
	}

	.inventoryDetails-btn-cen-top-two {
		margin-right: 72rpx;
	}

	.inventoryDetails-btn-cen-top-txt1 {
		font-size: 28rpx;
		color: #FFFFFF;
		font-weight: 400;
	}

	.inventoryDetails-btn-cen-top-txt2 {
		font-size: 28rpx;
		color: #FF9300;
	}

	.inventoryDetails-btn-cen-top-txt3 {
		font-size: 36rpx;
		color: #FF9300;
	}

	.inventoryDetails-btn-cen-bottom {
		font-size: 24rpx;
		color: #BBBBBB;
		font-weight: 400;
	}

	.inventoryDetails-btn-right {
		width: 168rpx;
		height: 68rpx;
		line-height: 68rpx;
		text-align: center;
		border-radius: 34rpx;
		border: 2rpx solid #FFFFFF;
		font-size: 24rpx;
		color: #FFFFFF;
	}

	.inventoryDetails-btn-right-two {
		border: none;
		background: #2ACE52;
		color: #FFFFFF;
	}
</style>
